package controller

import (
	"ginfast/configs"
	"ginfast/pkg/ginx"
	"os"
)

// UploadPicHandler 图片服务
func UploadPicHandler(c *ginx.Context) {
	filename := ""
	fileHead, err := c.FormFile("file")
	if err == nil {
		filename = configs.Public.Abs("upload", "picture", fileHead.Filename)
		os.MkdirAll(filename, os.ModePerm)
		err = c.SaveUploadedFile(fileHead, filename)
	}
	c.JSONWrite(ginx.H{"name": filename, "url": filename}, err)
}
